<%-- 
    Document   : customerviewproducts
    Created on : Feb 12, 2012, 9:59:59 PM
    Author     : Alex
--%>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <style type="text/css">
body {
	background-color: #000;
	background-image: url(bg.jpg);
	background-repeat: repeat-x;
}
body,td,th {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 7pt;
	color: #FFF;
}
h1 { font-family:Verdana, Geneva, sans-serif; font-size:24; text-align:center;}
h2 { font-family:Verdana, Geneva, sans-serif; font-size:11px; color:white;}
h3 { font-family:Verdana, Geneva, sans-serif; font-size:30; color:white; text-align:center;}

#menu{
    font: Verdana, Geneva, sans-serif;
    font-size: 10pt;
    color: white;
    position: absolute;
    top: 200px;
    left: 150px;
    text-align: left;
    font-style: bold;
}

#viewproduct{
    font: Verdana, Geneva, sans-serif;
    font-size: 10pt;
    color: white;
    position: absolute;
    top: 180px;
    left: 400px;
    text-align: left;
    font-style: bold;
}
   </style>
   <script language = "Javascript" type="text/javascript">

function OnBlurInput(blur){

			if(blur.value == "")
			{
		    blur.value = "";
			}

}

function OnBlurInputPass(blur){

			if(blur.value == "")
			{
		    blur.value = "";
			}

			if(blur.value == "Password" || blur.value == "Retype Password" )
			{
			blur.type = "text";
			blur.value = blur.defaultValue;
			}


}

function OnClickInput(click){

			if(click.value == click.defaultValue )
			{
				click.value = "";
			}


}

function OnClickInputPass(click){

			if(click.value == click.defaultValue )
			{
				click.value = "";
			}
			if(click.type == "text")
			{
			click.type = "password";

			}

}
</script>

        <h1>Customer View Products Page</h1> 
         <div id="menu">
            <h2> Customer Menu </h2>  </br> <% session.getAttribute("firstname");%> <%session.getAttribute("lastname");%>
         
         <strong><a href="customerviewproducts.jsp"><h2>View Products</h2></a><strong>
         <strong><a href="cart.jsp"><h2>Purchase Products</h2></a><strong>
         <strong><a href=""><h2>View Purchased Products</h2></a><strong>
         <strong><a href="customerviewprofile.jsp"><h2>View Profile</h2></a></strong>
         <strong><a href="LogoutServlet"><h2>LOGOUT</h2></a></strong>
 
         
          <%
    try {

String connectionURL = "jdbc:mysql://localhost:3306/databasefoobar";
// declare a connection by using Connection interface
Connection connection = null;
/* declare object of Statement interface that is used for executing sql
statements. */
Statement statement = null;
// declare a resultset that uses as a table for output data from tha table.
ResultSet rs = null;
ResultSet rs2= null;
// Load JBBC driver "com.mysql.jdbc.Driver"
Class.forName("com.mysql.jdbc.Driver").newInstance();
/* Create a connection by using getConnection() method that takes parameters
of string type connection url, user name and password to connect to database.*/
connection = DriverManager.getConnection(connectionURL, "root", "123456");
/* createStatement() is used for create statement object that is used for
sending sql statements to the specified database. */
statement = connection.createStatement();
 PreparedStatement pstmt = connection.prepareStatement("SELECT * FROM products ");
//pstmt.setString(1, "%"+name+"%");

 rs = pstmt.executeQuery();


// sql query to retrieve values from the secified table.
%>
   <input type="hidden" name="customerid" value=<%=session.getAttribute("id")%>>
   <br>Firstname:<%= session.getAttribute("firstname")%>
      <br>Middlename     <%= session.getAttribute("middlename")%>
<div id="search" style="left:400; top: 20;">
<form action="SearchResult.jsp" method="POST">    
            Search: <input type="text" name="search" /><input type="submit" value="Search" />
        </form><br>
 
        <div id="product" style="top: 99;left: 99; position: absolute;">
 <TABLE BORDER="1">
            <TR>
            
                <TH>Title</TH>
                <TH>Synopsis</TH>
                <TH>Price</TH>
                <TH>Type</TH>
                <TH>BUY!</TH>
            </TR>
            <% while(rs.next()){ %>
            <TR>
                <TD> <%= rs.getString(3) %></td>
                <TD> <%= rs.getString(4) %></TD>
                <TD> <%= rs.getString(5) %></TD>
                <TD> <%= rs.getString(6) %></TD>
            <form action="CartServlet" method="post">
                <input type="hidden" name="transid" value="1"/>
            <input type="hidden" name="customerid"  value="1" />
            <input type="hidden" name="productid"  value=<%= rs.getString(1) %> />
            <input type="hidden" name="customerid" value="1">
                <TD> <input type="submit" value="Add to cart" /></TD>
            </TR></form>
            <% } %>
        </TABLE>
        </div>
<%

// close all the connections.
rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
%>
</font>
<font size="+3" color="red"></b>
<%
out.println("Unable to connect to database.");
}
%>   
         
         
         
         
         

</html>
